package com.readnote.sellselfmail.action;
/**
 * @project readnote
 * @Title SellSelfMailAction.java
 * @author huxh
 * @date 2012-2-12
 **/

import java.util.Map;

import com.cr.backbone.action.AppBaseActionSupport;
import com.cr.backbone.model.SysFile;
import com.cr.backbone.util.UtilsDataDict;
import com.readnote.sellselfmail.model.SellSelfMail;
import com.readnote.sellselfmail.service.SellSelfMailService;

public class SellSelfMailAction extends AppBaseActionSupport{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -2022298171465397247L;
	private SellSelfMail sellSelfMail;
	private SellSelfMailService sellSelfMailService;

	private Long sid;		//关闭自我推荐邮件发送
	private String hrEmail;	//关闭自我推荐人事经理
	
	public String index(){
		getQuery().addOrderDesc("id");
		page = sellSelfMailService.getPage(getQuery(),page);
		return INDEX;
	}
	
	public String close(){
		if(sid !=null && sid >0 && hrEmail!=null && !"".equals(hrEmail) ){
			sellSelfMail = sellSelfMailService.get(sid);
			if(sellSelfMail.getHumanResourcesMail().equals( hrEmail)){
				if(sellSelfMail.getStatus().equals(UtilsDataDict.SELL_SELF_MAIL_STATUS_CLOSE)){
					this.addActionMessage("尊敬的："+hrEmail+"，你所找寻的自我推荐记录sid:"+sid+",已关闭，您可以补充回复意见.");
				}else {
					sellSelfMailService.updateSellSendClose(sellSelfMail);
					this.addActionMessage("尊敬的："+hrEmail+"，你所找寻的自我推荐记录sid:"+sid+",已经关闭，它将不再会对您投递自荐申请Email了.");
				}
				return "closeInput";
			}else{
				this.addActionMessage("尊敬的："+hrEmail+"，你所找寻的自我推荐记录sid:"+sid+",并未向您投递申请，您无权关闭此申请");
			}
		}
		this.addActionMessage("您所找寻的自我推荐记录不存在");	
		return "closeResult";
	}
	
	public String saveReply() {
		if(sellSelfMail!=null && !sellSelfMail.isNullRow()){
			sellSelfMailService.updateSellSendClose(sellSelfMail);
			this.addActionMessage("回复完毕，感谢您的宝贵建议！");
		}
		return "closeResult";
	}
	

	public String query(){
		
		getQuery().addOrderDesc("id");
		page = sellSelfMailService.getPage(getQuery(),page);
		return INDEX;
	}
	
	
	private Map<String,String> temp;
	public Map<String, String> getTemp() {
		return temp;
	}

	public void setTemp(Map<String, String> temp) {
		this.temp = temp;
	}

	public String input(){
		if(sellSelfMail!=null && !sellSelfMail.isNullRow())
			sellSelfMail = sellSelfMailService.get(sellSelfMail.getId());
		return INPUT;
	}
	
	public String save(){
		if(sellSelfMail.isNullRow()){
			
			sellSelfMail.setUser(getLoginInfo().getUser());
			SysFile sysFile=new SysFile(1l);//test 用于测试，默认取一个文件
			sellSelfMail.setSysFile(sysFile);
			sellSelfMailService.saveSellSelfMail(sellSelfMail);
		}else{
			
			sellSelfMailService.update(sellSelfMail);
		}
		return SUCCESS;
	}
	
	public String delete(){
		sellSelfMailService.delete(sellSelfMail);
		return SUCCESS;
	}


	public SellSelfMail getSellSelfMail() {
		return sellSelfMail;
	}


	public void setSellSelfMail(SellSelfMail sellSelfMail) {
		this.sellSelfMail = sellSelfMail;
	}


	public SellSelfMailService getSellSelfMailService() {
		return sellSelfMailService;
	}


	public void setSellSelfMailService(SellSelfMailService sellSelfMailService) {
		this.sellSelfMailService = sellSelfMailService;
	}

	public Long getSid() {
		return sid;
	}

	public void setSid(Long sid) {
		this.sid = sid;
	}

	public String getHrEmail() {
		return hrEmail;
	}

	public void setHrEmail(String hrEmail) {
		this.hrEmail = hrEmail;
	}


	
}
